import os


class LogFinder:
    file_count = 0
    target_line_count = 0

    def find_in_dir(self, dir_path):
        self.recursive_play(dir_path)
        print("file_count:", self.file_count)
        print("target_line_count:", self.target_line_count)

    def find_str(self, file_path):
        with open(file_path, encoding='utf-8', mode='r') as file:
            line = file.readline()
            while line:
                if line.__contains__("getAudioDataResult,return_value"):
                    if not line.__contains__("getAudioDataResult,return_value:0") and not line.__contains__(
                            "getAudioDataResult,return_value:10024") and line.__contains__(
                            "getAudioDataResult,return_value:10004"):
                        print(file_path, line)
                        self.target_line_count += 1
                line = file.readline()

    def recursive_play(self, path):
        files = os.listdir(path)
        if len(files) == 0:
            return
        for file in files:
            new_path = '\\'.join([path, file])
            # 文件
            if os.path.isfile(new_path):
                if file.startswith("TestISS_"):
                    self.file_count += 1
                    self.find_str(new_path)
            # 文件夹
            else:
                self.recursive_play(new_path)


if __name__ == '__main__':
    logFinder = LogFinder()
    logFinder.find_in_dir("D:/test_data/TestData/sentence_split/cloud_apt_02_2_short")
